var t = require("../../../mybehaviors/location/location"), e = getApp();

Page({
    behaviors: [ t ],
    data: {
        locationStatus: !1,
        locationMore: !1,
        activeNames: [],
        query: {
            longitude: "",
            latitude: "",
            id: "",
            basic_info: 1
        },
        zIndex: 100,
        lately: [],
        optionId: 0,
        total: 1,
        favorite: !1,
        goodsActive: 0,
        beginStatus: 1,
        aroundGoods: {},
        count: "",
        shopAddress: {},
        getGoods: {},
        now: "",
        productIndex: 0,
        goodsOptionOpen: !1,
        showKefu: !1,
        customer_open: "",
        cservice: "",
        service_mobile: "",
        service_QRcode: "",
        presentTime: "",
        formatbeginTime: "",
        formatEndTime: "",
        formatPoints: "",
        validBeginDate: "",
        validEndDate: "",
        afterTime: "",
        beforeTime: "",
        computingFlase: !1,
        plugin_setting: {},
        iPnoneBottomBol: !1,
        description: "",
        goodsDesc: ""
    },
    onLoad: function(t) {
        t.goodsId && this.setData({
            "query.id": Number(t.goodsId),
            presentTime: new Date().getTime()
        }), this.getKefu(), this.goodsdetails(), this.getiPnoneBottom();
    },
    onReady: function() {
        var t = this;
        if (!this.data.query.latitude && !this.data.query.latitude) try {
            this._getLocation(function(e, o) {
                t.setData({
                    "query.latitude": o.lat,
                    "query.longitude": o.lng
                }), t.goodsdetails();
            });
        } catch (t) {
            this.goodsdetails(), console.log(t);
        }
    },
    onShow: function() {},
    goodsdetails: function() {
        var t = this;
        "" === this.data.query.latitude && "" === this.data.query.longitude ? this.setData({
            locationMore: !1
        }) : this.setData({
            locationMore: !0
        });
        var o = e.getNetAddresss("goods.goods.get-goods-page");
        e._postNetWork({
            url: o,
            data: this.data.query,
            success: function(o) {
                var a = o.data;
                if (1 == a.result) {
                    var i, n, d, s, r, u, l, c, g, v, m, h, f, p, T, D = a.data.get_goods, _ = null === (i = a.basic_info) || void 0 === i ? void 0 : i.plugin_setting, b = null === (n = a.data.plugin) || void 0 === n || null === (d = n.travel_around.data) || void 0 === d ? void 0 : d.travel_around_goods, y = null === (s = b.content) || void 0 === s ? void 0 : s.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;"'), w = null === (r = D.content) || void 0 === r ? void 0 : r.replace(/\<img/gi, '<img style="max-width:100%;height:auto;display:block;"');
                    t.setData({
                        shopAddress: null === (u = a.data.plugin) || void 0 === u || null === (l = u.travel_around.data) || void 0 === l ? void 0 : l.shop_address,
                        aroundGoods: b,
                        favorite: !!a.data.is_favorite && 1 == a.data.is_favorite.status,
                        count: null === (c = a.data.plugin) || void 0 === c || null === (g = c.travel_around.data) || void 0 === g ? void 0 : g.count,
                        getGoods: D,
                        lately: null === (v = a.data.plugin) || void 0 === v || null === (m = v.travel_around.data) || void 0 === m ? void 0 : m.lately,
                        optionId: null == D ? void 0 : D.has_many_options[0].id,
                        plugin_setting: _,
                        formatbeginTime: t.timestampToTime(b.beginTime),
                        formatEndTime: t.timestampToTime(b.endTime),
                        formatPoints: t.points(b.endTime),
                        validBeginDate: t.timestampToTime(b.validBeginDate),
                        validEndDate: t.timestampToTime(b.validEndDate),
                        afterTime: t.afterTimeData(b.beginTime),
                        computingFlag: t.computingTime(t.data.presentTime, b.endTime),
                        beforeTime: t.beforeDay(b.endTime),
                        description: y,
                        goodsDesc: w
                    });
                    var q = new Date().getTime();
                    t.data.aroundGoods.beginTime > q && t.setData({
                        beginStatus: 0
                    }), 1 !== (null === (h = t.data.plugin_setting) || void 0 === h || null === (f = h.travel_around) || void 0 === f ? void 0 : f.is_ios_sell) && "1" !== (null === (p = t.data.plugin_setting) || void 0 === p || null === (T = p.travel_around) || void 0 === T ? void 0 : T.is_ios_sell) || "ios" === e.isIosOrAndroid() && t.setData({
                        beginStatus: -1
                    }), t.goodsOption();
                } else wx.showModal({
                    content: a.msg,
                    success: function(t) {
                        t.confirm && wx.navigateBack({
                            delta: 1
                        });
                    }
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    goodsOption: function() {
        var t = this, o = e.getNetAddresss("plugin.travel-around.frontend.goods.option"), a = {
            goods_id: this.data.query.id
        };
        e._postNetWork({
            url: o,
            data: a,
            success: function(e) {
                var o, a, i = e.data;
                1 == i.result ? (t.setData({
                    categoriesGoodsList: i.data
                }), t.getArrEqual(i.data, null === (o = t.data) || void 0 === o || null === (a = o.getGoods) || void 0 === a ? void 0 : a.has_many_options)) : wx.showToast({
                    icon: "none",
                    title: i.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getArrEqual: function(t, e) {
        if (null !== t) {
            for (var o = this.data.getGoods, a = 0; a < e.length; a++) 0 == t[e[a].id] && (o.has_many_options[a].stock = 0);
            this.setData({
                getGoods: o
            });
        } else this.setData({
            beginStatus: -1
        });
    },
    timestampToTime: function(t) {
        if (t && 0 != t) {
            var e = new Date(Number(t));
            return e.getFullYear() + "/" + ((e.getMonth() + 1 < 10 ? "0" + (e.getMonth() + 1) : e.getMonth() + 1) + "/") + (this.change(e.getDate()) + " ") + (this.change(e.getHours()) + ":") + this.change(e.getMinutes());
        }
    },
    points: function(t) {
        var e = new Date(Number(t)), o = new Date(new Date(e).toLocaleDateString()).getTime();
        return new Date(new Date().toLocaleDateString()).getTime() === Number(o);
    },
    computingTime: function(t, e) {
        if (Number(e)) {
            var o = Number(t) - Number(e);
            return (0 === o || o > 0) && (this.setData({
                beginStatus: 2
            }), !0);
        }
    },
    beforeDay: function(t) {
        if (Number(t)) return t - Number(this.data.presentTime);
    },
    beforeDayTime: function(t) {
        if (Number(t)) {
            var e = new Date(Number(t));
            return e = +e - 864e5, e = new Date(Number(e)), Number(e);
        }
    },
    afterTimeData: function(t) {
        if (Number(t)) return t - Number(this.data.presentTime);
    },
    navigation: function(t) {
        var o = t.currentTarget.dataset, a = o.latitude, i = o.longitude, n = o.shopaddress;
        console.log(a, i, n);
        var d = e.BMapTransqqMap(parseFloat(i), parseFloat(a));
        wx.openLocation({
            latitude: d.lat,
            longitude: d.lng,
            name: n,
            scale: 18
        });
    },
    callStore: function(t) {
        var e = t.currentTarget.dataset.phone;
        wx.makePhoneCall({
            phoneNumber: e
        });
    },
    tapIndex: function() {
        wx.navigateTo({
            url: "/packageF/tourAround/travelIndex/travelIndex"
        });
    },
    storeNav: function() {
        wx.navigateTo({
            url: "/packageF/tourAround/tourAroundStoreList/tourAroundStoreList?goodsId=".concat(this.data.query.id, "&latitude=").concat(this.data.query.latitude, "&longitude=").concat(this.data.query.longitude)
        });
    },
    clickChat: function() {
        this.setData({
            showKefu: !0
        });
    },
    getiPnoneBottom: function() {
        try {
            wx.getStorageSync("iPhoneBottom") && this.setData({
                iPnoneBottomBol: !0
            });
        } catch (t) {}
    },
    getKefu: function() {
        var t, o = this, a = null === (t = this.data.query) || void 0 === t ? void 0 : t.id, i = e.getNetAddresss("goods.customer-service.index");
        e._postNetWork({
            url: i,
            data: {
                goods_id: a
            },
            success: function(t) {
                var e = t.data;
                1 == e.result && (o.setData({
                    customer_open: 0 != e.data.customer_open,
                    showKefu: !1,
                    cservice: e.data.cservice,
                    service_QRcode: e.data.service_QRcode,
                    service_mobile: e.data.service_mobile
                }), console.log(o.data.cservice));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    onFavorite: function() {
        var t = this, o = "", a = !this.data.favorite;
        o = a ? e.getNetAddresss("member.member-favorite.store") : e.getNetAddresss("member.member-favorite.destroy"), 
        o += "&goods_id=" + this.data.query.id, e._getNetWork({
            url: o,
            success: function(e) {
                var o = e.data;
                t.setData({
                    favorite: a
                }), wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 3e3
                });
            },
            fail: function(t) {}
        });
    },
    specificationOn: function(t) {
        var e = t.currentTarget.dataset, o = e.index, a = e.id;
        this.setData({
            productIndex: o,
            optionId: a
        });
    },
    onPreorder: function() {
        if (0 === this.data.aroundGoods.ecommerce) {
            var t = "&goodsId=".concat(this.data.query.id, "&optionsId=").concat(this.data.optionId, "&total=").concat(this.data.total, "&orderShowDate=").concat(this.data.aroundGoods.orderShowDate);
            wx.navigateTo({
                url: "/packageD/buy/myOrder_v2/myOrder_v2?tag=tourAround" + t
            });
        }
    },
    goodsLikeOn: function(t) {
        var e = t.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + e
        });
    },
    change: function(t) {
        return t < 10 ? "0" + t : t;
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        var t, e, o, a, i;
        return {
            title: null === (t = this.data.getGoods) || void 0 === t ? void 0 : t.title,
            imageUrl: null === (e = this.data.getGoods) || void 0 === e ? void 0 : e.thumb,
            path: "packageF/tourAround/tourAroundGoodsDetails/tourAroundGoodsDetails?goodsId=".concat(null === (o = this.data.query) || void 0 === o ? void 0 : o.id, "&latitude=").concat(null === (a = this.data.query) || void 0 === a ? void 0 : a.latitude, "&longitude=").concat(null === (i = this.data.query) || void 0 === i ? void 0 : i.longitude)
        };
    },
    onShareTimeline: function() {
        var t, e, o, a, i;
        return {
            title: null === (t = this.data.getGoods) || void 0 === t ? void 0 : t.title,
            imageUrl: null === (e = this.data.getGoods) || void 0 === e ? void 0 : e.thumb,
            path: "packageF/tourAround/tourAroundGoodsDetails/tourAroundGoodsDetails?goodsId=".concat(null === (o = this.data.query) || void 0 === o ? void 0 : o.id, "&latitude=").concat(null === (a = this.data.query) || void 0 === a ? void 0 : a.latitude, "&longitude=").concat(null === (i = this.data.query) || void 0 === i ? void 0 : i.longitude)
        };
    }
});